###### Maintext: Figure 2
###### Coefficient Distribution for Direct and Indirect Taxes on Vertical Accountability and Corruption
gc()
rm(list = ls())
set.seed(12345)
setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) # Note: if you are not using R Studio this command will not work, set WD to source file location manually

source("functions.R")
source("data/working_eba_function_current.R") 
require(pacman)
pacman::p_load(plm, sandwich, clubSandwich, lmtest, 
               ggplot2, numbers, dplyr, Hmisc, formattable, 
               htmltools, webshot, ggpubr, panelView, fixest, plyr, 
               scales, DataCombine)
require(webshot)
require(stringr)
date <- paste(data.table::tstrsplit(Sys.Date(), "-")[c(2:3, 1)], collapse = "")
load("data/cleaned/vat_panel_cleaned15Nov.RData")


## Set hyperparameters

numSims <- 4943

######################## MAIN RESULTS ###########################
# Choose 1, 2, 3, 4, and 5 added variable combinations

depUse <- c("acc_vert", "v2x_corr")
depNames <- c("Vertical Accountability", "Control of Corruption Index")
mainRes <- eba_fit(dep.vars = depUse, 
                 dep.names = depNames,
                 samp.num = numSims,
                 data = dfMerge)
save(list = c("mainRes"), 
     file = paste0("results/main_xnat_results.RData"))

load("results/main_xnat_results.RData")
mainRes$acc_vert$plot$theme$text$size <- 16
mainRes$acc_vert$plot$theme$title$size <- 16
mainRes$acc_vert$plot$theme$axis.title$size <- 16
mainRes$acc_vert$plot$theme$axis.text$size <- 16

mainRes$v2x_corr$plot$theme$text$size <- 16
mainRes$v2x_corr$plot$theme$title$size <- 16
mainRes$v2x_corr$plot$theme$axis.title$size <- 16
mainRes$v2x_corr$plot$theme$axis.text$size <- 16

pMain <- ggarrange(mainRes$acc_vert$plot, 
                   mainRes$v2x_corr$plot, 
                   common.legend = T, legend = "bottom")
pdf(file = paste0("figures/fig_2.pdf"), 
    width = 12, height = 8)
print(pMain)
dev.off()



